import _ from 'lodash';
import { getPolluteChart } from '@/services/polluteManage';

const PolluteModel = {
  namespace: 'polluteManage',
  state: {
    polluteData: [],
    loading: false,
  },
  effects: {
    *getData({ payload }, { call, put, select }) {
      const response = yield call(getPolluteChart, { ...payload });
      const polluteChart = _.get(response, 'data', []);
      console.log(polluteChart);

      yield put({
        type: 'updateDataSet',
        payload: {
          polluteChart,
        },
      });
    },
  },
  reducers: {
    updateDataSet(state, { payload }) {
      return {
        ...state,
        polluteData: payload.polluteChart,
        loading: false,
      };
    },
  },
};

export default PolluteModel;
